﻿<%@ taglib uri="/mytaglib" prefix="ct"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/includes.jsp"%>
<script>
	$(document).ready(function() {
		$(":checkbox,button").click(function(event){
			event.stopPropagation();//阻止冒泡事件，上级的单击事件不会被调用
			}); 
		$(":checkbox").parent().click(function(event){
			event.stopPropagation();//阻止冒泡事件，上级的单击事件不会被调用
			}); 
		$("#file").fileinput({
			enctype: 'multipart/form-data',	
			uploadAsync:false,
			theme:'explorer',
			maxFileCount: 100,
			initialCaption: "请上传台账文件",//文本框初始话value
			language: 'zh',
			uploadUrl:'../accountBook/ajax/fileImport',
			uploadExtraData:{id:'11',name:'zdm'},
			previewFileType:'any',
			allowedFileExtensions : ['xlsx','xls'],//接收的文件后缀
	        showUpload: false, //是否显示上传按钮
	        showCaption: true//是否显示标题
	        //browseClass: "btn btn-primary"//按钮样式             
	        // previewFileIcon: "<i class='glyphicon glyphicon-king'></i>" 
			}).on('fileuploaded', function(event, data, previewId, index) {
			    var form = data.form, files = data.files, extra = data.extra,
		        response = data.response, reader = data.reader;
			    //debugger
			    parseResult(data.response,function(obj){
			    	searchAccountBook();
			    },function(obj){
			    	//searchAccountBook();
			    });
		    console.log('File uploaded triggered');
		});		
	});
	
	function changeCheck(id){
		$("#"+id).click();
	}
	
	function showAccountBookDetail(id){
		myAjaxSumbmit('', '/accountBook/ajax/entity?id=' + id, '', function(
				data) {

			document.getElementById("editAccountBookForm").reset();
			myValidate.resetForm();
			$('#id').val(id);
			$('#contractNum').val(data.contractNum);
			$('#reciveTime').val(data.reciveTime);
			$('#contractTime').val(data.contractTime);
			$('#pickupTime').val(data.pickupTime);
			$('#buyOrg').val(data.buyOrg);
			$('#carLevel').val(data.carLevel);
			$('#seatNum').val(data.seatNum);
			$('#operateLine').val(data.operateLine);
			$('#saleCompany').val(data.saleCompany);
			$('#fuelType').val(data.fuelType);
			$('#carType').val(data.carType);
			$('#num').val(data.num);
			$('#saleUnitPrice').val(data.saleUnitPrice);
			$('#salePrice').val(data.salePrice);
			$('#buyUnitPrice').val(data.buyUnitPrice);
			$('#buyPrice').val(data.buyPrice);
			$('#grossProfit').val(data.grossProfit);
			$('#deposit').val(data.deposit);
			$('#depositPayTime').val(data.depositPayTime);
			$('#receivables').val(data.receivables);
			$('#payment').val(data.payment);
			$('#cdPrice').val(data.cdPrice);
			$('#ticketInto').val(data.ticketInto);
			$('#ticketOut').val(data.ticketOut);

			$("#editAccountBookModalLabel").text("查看");
			$("#editSaveAccountBookBtn").hide();
			$('#editAccountBookModal').removeClass("modal-warning");
			$('#editAccountBookModal').addClass("modal-info");
			$(".has-error").removeClass('has-error');
			
			$('#editAccountBookModal').modal('show');

		});
	}
	
	function toggleAll(){
		$(":checkbox").prop("checked",$("#allClickTag").is(':checked'));
	}
	
	var form = $("#editAccountBookForm");
	var myValidate = form
	.validate({
		showErrors : function(errorMap, errorList) {
			for (var i = 0; i < errorList.length; i++) {
				$(errorList[i].element).parent().parent().addClass(
						'has-error');
			}
			this.defaultShowErrors();
		},
		success : function(label, element) {
			$(element).parent().parent().removeClass('has-error');
		}
	});
	
	function toAccountBookAdd(){

		document.getElementById("editAccountBookForm").reset();
		myValidate.resetForm();
		$(".has-error").removeClass('has-error');

		$("#editAccountBookModalLabel").text("新增");
		$("#editSaveAccountBookBtn").show();
		$("#editSaveAccountBookBtn").attr("onclick", "saveAccountBookAdd()");
		$('#editAccountBookModal').removeClass("modal-warning");
		$('#editAccountBookModal').removeClass("modal-info");
		
		$('#editAccountBookModal').modal('show');
	}	
	
	function saveAccountBookAdd(){

		if (form.valid()) {
			myAjaxSumbmit('editAccountBookForm',
					'/accountBook/ajax/save',
					'/accountBook/list', function() {
						$('#editAccountBookModal').modal('hide');
					});
		}
	}
	
	function toAccountBookModify(id){
		myAjaxSumbmit('', '/accountBook/ajax/entity?id=' + id, '', function(
				data) {

			document.getElementById("editAccountBookForm").reset();
			myValidate.resetForm();
			$('#id').val(id);
			$('#contractNum').val(data.contractNum);			
			$('#reciveTime').val(data.reciveTime);			
			$('#contractTime').val(data.contractTime);			
			$('#pickupTime').val(data.pickupTime);			
			$('#buyOrg').val(data.buyOrg);			
			$('#carLevel').val(data.carLevel);			
			$('#seatNum').val(data.seatNum);			
			$('#operateLine').val(data.operateLine);			
			$('#saleCompany').val(data.saleCompany);			
			$('#fuelType').val(data.fuelType);			
			$('#carType').val(data.carType);			
			$('#num').val(data.num);			
			$('#saleUnitPrice').val(data.saleUnitPrice);			
			$('#salePrice').val(data.salePrice);			
			$('#buyUnitPrice').val(data.buyUnitPrice);			
			$('#buyPrice').val(data.buyPrice);			
			$('#grossProfit').val(data.grossProfit);			
			$('#deposit').val(data.deposit);			
			$('#depositPayTime').val(data.depositPayTime);			
			$('#receivables').val(data.receivables);			
			$('#payment').val(data.payment);			
			$('#cdPrice').val(data.cdPrice);			
			$('#ticketInto').val(data.ticketInto);			
			$('#ticketOut').val(data.ticketOut);			
			
			$("#editAccountBookModalLabel").text("修改");
			$('#editAccountBookModal').addClass("modal-warning");
			$('#editAccountBookModal').removeClass("modal-info");
			$("#editSaveAccountBookBtn").attr("onclick", "modifyAccountBook(" + id + ")");
			$("#editSaveAccountBookBtn").show();
			$(".has-error").removeClass('has-error');
			$('#editAccountBookModal').modal('show');

		});
	}
	
	function modifyAccountBook(id) {
		if (!(id === undefined) && id != '') {
			if (form.valid()) {
				myAjaxSumbmit('editAccountBookForm',
						'/accountBook/ajax/update',
						'/accountBook/list', function() {
							$('#editAccountBookModal').modal('hide');
						});
			}
		} else {
			alert("请选择修改项！");
		}
	}
	
	function delAccountBookConfirm(id) {
		$("#delConfirmContent").html("确认删除这个台账？");
		$("#delConfirmButton").attr("onclick", "delAccountBook(" + id + ")");
		$('#delModal').modal('show');
	}
	
	function delAccountBook(id) {
		if (!(id === undefined) && id != '') {
			myAjaxSumbmit('noData',
					'/accountBook/ajax/del?id=' + id, '/accountBook/list',
					function() {
						$('#delModal').modal('hide');
					});
		} else {
			alert("请选择删除项！");
		}
	}
	
	function delAccountBooks(ids) {
			myAjaxSumbmit('accountBookListForm',
					'/accountBook/ajax/delAll', '/accountBook/list',
					function() {
						$('#delModal').modal('hide');
					});		
	}
	
	function delAllAccountBookConfirm(){
		var len=$(":checkbox[name=ids]:checked").length;
		if(len>0){
			$("#delConfirmContent").html("确认删除这些台账？");
			$("#delConfirmButton").attr("onclick", "delAccountBooks()");
			$('#delModal').modal('show');
		}else{
			alert("请选择删除项！");
		}
	}
	
	function searchAccountBook(){
		mySubmit('searchAccountBookForm', '/accountBook/list');
	}
	
</script>



<div class="box-header">
	<form id="searchAccountBookForm">
		<div class="col-sm-2">
			<h3 class="box-title">台账管理列表</h3>
		</div>
		<div class="col-sm-2">
			<input type="text" name="contractNum" class="form-control input-sm pull-right" placeholder="合同号" value="${searchAccountBookPagingVo.contractNum }">
		</div>
		<div class="col-sm-2">
			<input type="text" name="buyOrg" class="form-control input-sm pull-right" placeholder="购车单位" value="${searchAccountBookPagingVo.buyOrg}">
		</div>
		<div class="col-sm-2">
			<div class="input-group">
				<input type="text" name="saleCompany" class="form-control input-sm pull-right" placeholder="供车厂家" value="${searchAccountBookPagingVo.saleCompany}">
				<div class="input-group-btn">
					<button class="btn btn-sm btn-default" type="button" onclick="searchAccountBook()">
						<i class="fa fa-search"></i>
					</button>
				</div>
			</div>
		</div>
	</form>
	<div class="box-tools">
		<button type="button" onclick="delAllAccountBookConfirm()" class="btn btn-danger btn-flat">批量删除</button>
		<button type="button" onclick="toAccountBookAdd()" class="btn btn-primary btn-flat">新增</button>
	</div>
</div>

<!-- /.box-header -->
<div class="box-body table-responsive no-padding">

	<form id="accountBookListForm">
		<table class="table table-hover  table-bordered">
			<tbody>
				<tr>
					<th width="5%" onclick="changeCheck('allClickTag')">全选<input type="checkbox" onchange="toggleAll()" id="allClickTag"></th>
					<th>合同号</th>
					<th>收件日期</th>
					<th>合同签订时间</th>
					<th>提车时间</th>
					<th>购车单位</th>
					<th>等级</th>
					<th>座位数</th>
					<th>经营线路</th>
					<th>供车厂家</th>
					<th>燃料类型</th>
					<th>车型</th>
					<th>数量</th>
					<th>销售单价</th>
					<th>销售合价</th>
					<th>进货单价</th>
					<th>进价合计</th>
					<th>毛利</th>
					<th>订金</th>
					<th>订金支付时间</th>
					<th>收款情况</th>
					<th>付款情况</th>
					<th>光盘价格</th>
					<th>进票</th>
					<th>出票</th>
				</tr>
			</tbody>

			<c:forEach var="accountBook" items="${page.list}">

				<tr onclick="showAccountBookDetail(${accountBook.id})" title="单击查看详情" id="accountBook${accountBook.id}">
					<td align="center" onclick="changeCheck('id${accountBook.id}')"><input type="checkbox" id="id${accountBook.id}" name="ids" title="选择" value="${accountBook.id}"></td>

					<td>${accountBook.contractNum}</td>
					<td><fmt:formatDate value="${accountBook.reciveTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td><fmt:formatDate value="${accountBook.contractTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td><fmt:formatDate value="${accountBook.pickupTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td>${accountBook.buyOrg}</td>
					<td>${accountBook.carLevel}</td>
					<td>${accountBook.seatNum}</td>
					<td>${accountBook.operateLine}</td>
					<td>${accountBook.saleCompany}</td>
					<td>${accountBook.fuelType}</td>
					<td>${accountBook.carType}</td>
					<td>${accountBook.num}</td>
					<td>${accountBook.saleUnitPrice}</td>
					<td>${accountBook.salePrice}</td>
					<td>${accountBook.buyUnitPrice}</td>
					<td>${accountBook.buyPrice}</td>
					<td>${accountBook.grossProfit}</td>
					<td>${accountBook.deposit}</td>
					<td><fmt:formatDate value="${accountBook.depositPayTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td>${accountBook.receivables}</td>
					<td>${accountBook.payment}</td>
					<td>${accountBook.cdPrice}</td>
					<td>${accountBook.ticketInto}</td>
					<td>${accountBook.ticketOut}</td>
					<td>
						<div class="col-sm-4" align="center">
							<button type="button" onclick="toAccountBookModify('${accountBook.id}')" class="btn btn-warning btn-flat btn-shorter">修改</button>
						</div>
						<div class="col-sm-4" align="center">
							<button type="button" onclick="delAccountBookConfirm('${accountBook.id}')" class="btn btn-danger btn-flat btn-shorter">删除</button>
						</div>
					</td>
				</tr>

			</c:forEach>

		</table>
	</form>

</div>
<!-- /.box-body -->

<div class="box-footer clearfix">
	<ct:paging pageNo="${page.pageNo}" recordCount="${page.recordCount}" pageSize="${page.pageSize}" url="/accountBook/list" />
</div>

<div class="row">
	<div class="form-group">
		<label class="control-label col-sm-1">选择导入文件</label>
		<div class="col-sm-3">
			<input id="file" name="file" type="file" class="file form-control" data-preview-file-type="text" multiple="multiple">
		</div>
	</div>
</div>

<!-- Modal -->
<div class="modal fade " id="editAccountBookModal" role="dialog" aria-labelledby="editAccountBookModalLabel" data-backdrop="false">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="closeModal('editAccountBookModal')">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="editAccountBookModalLabel">新增</h4>
			</div>
			<div class="modal-body" id="editAccountBookModalBody">
				<form class="form-horizontal" id="editAccountBookForm">
					<input type="hidden" id="id" name="id">
					<div class="box-body">
						<div class="form-group ">
							<label for="contractNum" class="col-sm-2 control-label">合同号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="contractNum" name="contractNum" placeholder="合同号">
							</div>
						</div>
						<div class="form-group ">
							<label for="reciveTime" class="col-sm-2 control-label">收件日期</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="reciveTime" name="reciveTime" placeholder="收件日期">
							</div>
						</div>
						<div class="form-group ">
							<label for="contractTime" class="col-sm-2 control-label">合同签订时间</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="contractTime" name="contractTime" placeholder="合同签订时间">
							</div>
						</div>
						<div class="form-group ">
							<label for="pickupTime" class="col-sm-2 control-label">提车时间</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="pickupTime" name="pickupTime" placeholder="提车时间">
							</div>
						</div>
						<div class="form-group ">
							<label for="buyOrg" class="col-sm-2 control-label">购车单位</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="buyOrg" name="buyOrg" placeholder="购车单位">
							</div>
						</div>
						<div class="form-group ">
							<label for="carLevel" class="col-sm-2 control-label">等级，中型中，大高一等</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="carLevel" name="carLevel" placeholder="等级，中型中，大高一等">
							</div>
						</div>
						<div class="form-group ">
							<label for="seatNum" class="col-sm-2 control-label">座位数</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="seatNum" name="seatNum" placeholder="座位数">
							</div>
						</div>
						<div class="form-group ">
							<label for="operateLine" class="col-sm-2 control-label">经营线路</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="operateLine" name="operateLine" placeholder="经营线路">
							</div>
						</div>
						<div class="form-group ">
							<label for="saleCompany" class="col-sm-2 control-label">供车厂家</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="saleCompany" name="saleCompany" placeholder="供车厂家">
							</div>
						</div>
						<div class="form-group ">
							<label for="fuelType" class="col-sm-2 control-label">燃料类型</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="fuelType" name="fuelType" placeholder="燃料类型">
							</div>
						</div>
						<div class="form-group ">
							<label for="carType" class="col-sm-2 control-label">车型</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="carType" name="carType" placeholder="车型">
							</div>
						</div>
						<div class="form-group ">
							<label for="num" class="col-sm-2 control-label">数量</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="num" name="num" placeholder="数量">
							</div>
						</div>
						<div class="form-group ">
							<label for="saleUnitPrice" class="col-sm-2 control-label">销售单价</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="saleUnitPrice" name="saleUnitPrice" placeholder="销售单价">
							</div>
						</div>
						<div class="form-group ">
							<label for="salePrice" class="col-sm-2 control-label">销售合价</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="salePrice" name="salePrice" placeholder="销售合价">
							</div>
						</div>
						<div class="form-group ">
							<label for="buyUnitPrice" class="col-sm-2 control-label">进货单价</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="buyUnitPrice" name="buyUnitPrice" placeholder="进货单价">
							</div>
						</div>
						<div class="form-group ">
							<label for="buyPrice" class="col-sm-2 control-label">进价合计</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="buyPrice" name="buyPrice" placeholder="进价合计">
							</div>
						</div>
						<div class="form-group ">
							<label for="grossProfit" class="col-sm-2 control-label">毛利</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="grossProfit" name="grossProfit" placeholder="毛利">
							</div>
						</div>
						<div class="form-group ">
							<label for="deposit" class="col-sm-2 control-label">订金</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="deposit" name="deposit" placeholder="订金">
							</div>
						</div>
						<div class="form-group ">
							<label for="depositPayTime" class="col-sm-2 control-label">订金支付时间</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="depositPayTime" name="depositPayTime" placeholder="订金支付时间">
							</div>
						</div>
						<div class="form-group ">
							<label for="receivables" class="col-sm-2 control-label">收款情况</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="receivables" name="receivables" placeholder="收款情况">
							</div>
						</div>
						<div class="form-group ">
							<label for="payment" class="col-sm-2 control-label">付款情况</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="payment" name="payment" placeholder="付款情况">
							</div>
						</div>
						<div class="form-group ">
							<label for="cdPrice" class="col-sm-2 control-label">光盘价格</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="cdPrice" name="cdPrice" placeholder="光盘价格">
							</div>
						</div>
						<div class="form-group ">
							<label for="ticketInto" class="col-sm-2 control-label">进票</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="ticketInto" name="ticketInto" placeholder="进票">
							</div>
						</div>
						<div class="form-group ">
							<label for="ticketOut" class="col-sm-2 control-label">出票</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="ticketOut" name="ticketOut" placeholder="出票">
							</div>
						</div>
					</div>
					<!-- /.box-body -->
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default " data-dismiss="modal" onclick="closeModal('editAccountBookModal')">关闭</button>
				<button type="button" class="btn btn-primary" onclick="saveAccountBookAdd()" id="editSaveAccountBookBtn">保存</button>
			</div>

		</div>
	</div>
</div>
